

package org.tools;

import java.util.ArrayList;
import java.util.List;

// Referenced classes of package org.tools:
//			RuleUtil

public class LineAreaJudgeV2
{

	private List lineLs;
	private double width;

	public LineAreaJudgeV2(String points, String width)
	{
		lineLs = new ArrayList();
		this.width = 0.0D;
		createArea(points);
		this.width = Double.parseDouble(width);
	}

	public void createArea(String points)
	{
		String ps[] = points.split(";");
		double dx1 = 0.0D;
		double dy1 = 0.0D;
		double dx0 = 0.0D;
		double dy0 = 0.0D;
		for (int i = 1; i < ps.length; i++)
		{
			String cord1[] = ps[i].split(",");
			dx1 = Double.parseDouble(cord1[0]);
			dy1 = Double.parseDouble(cord1[1]);
			String cord0[] = ps[i - 1].split(",");
			dx0 = Double.parseDouble(cord0[0]);
			dy0 = Double.parseDouble(cord0[1]);
			Double line[] = new Double[4];
			line[0] = Double.valueOf(dx0);
			line[1] = Double.valueOf(dy0);
			line[2] = Double.valueOf(dx1);
			line[3] = Double.valueOf(dy1);
			lineLs.add(line);
		}

	}

	public boolean isInArea(String x, String y)
	{
		for (int i = 0; i < lineLs.size(); i++)
		{
			Double linePoints[] = (Double[])lineLs.get(i);
			double r = RuleUtil.minDistenceOfPoint2Line(linePoints[0].doubleValue(), linePoints[1].doubleValue(), linePoints[2].doubleValue(), linePoints[3].doubleValue(), Double.parseDouble(x), Double.parseDouble(y));
			if (r <= width)
				return true;
		}

		return false;
	}

	public boolean isInArea(float x, float y)
	{
		return isInArea((new StringBuilder(String.valueOf(x))).toString(), (new StringBuilder(String.valueOf(y))).toString());
	}

	public static void main(String args[])
	{
		LineAreaJudgeV2 line = new LineAreaJudgeV2("118.126592,30.130026;118.126692,30.130126", "100");
		System.out.println(line.isInArea("118.126592", "30.130027"));
	}
}
